/* eslint-disable no-unused-vars */
import a from'./img/01.jpeg';
import b from'./img/02.jpeg';
import c from'./img/03.jpeg';
import d from'./img/04.jpeg';
let data = [a, b, c, d];
let img = document.querySelector('img');
let left = document.querySelector('.left');
let right = document.querySelector('.right');
let change = document.querySelector('.change');
let all = document.querySelector('.all');
let point = []; //图片下方的圆点集合
data.forEach((v, i) => {
    //自动生成圆点
    point[i] = document.createElement('div');
    point[i].className = 'point';
    point[i].dataset.i = i;
    change.appendChild(point[i]);
});
all.addEventListener('click', (e) => {
    //事件代理
    if (e.target.className === 'point') {
        let index = e.target.getAttribute('data-i');
        img.src = data[index];
    }
    if (e.target.className === 'left') {
        let i = data.indexOf(img.getAttribute('src'));
        if (i > 0) img.src = data[i - 1];
        else img.src = data[i - 1 + data.length];
    }
    if (e.target.className === 'right') {
        let i = data.indexOf(img.getAttribute('src'));
        if (i < data.length - 1) img.src = data[i + 1];
        else img.src = data[i + 1 - data.length];
    }
    if (e.target.localName === 'button') {
        let timer = setInterval(() => {
            //自动轮播
            let i = data.indexOf(img.getAttribute('src'));
            if (i < data.length - 1) img.src = data[i + 1];
            else img.src = data[i + 1 - data.length];
        }, 1500);
    }
});